/*time update*/
updateTime()

function updateTime() {
  let time = new Date()
  document.querySelector('.time').innerHTML = time.getFullYear() + '-' + (formateData(time.getMonth() + 1)) + '-' + formateData(time.getDate()) + ' '
    + formateData(time.getHours()) + ':' + formateData(time.getMinutes()) + ':' + formateData(time.getSeconds())+'&nbsp&nbsp&nbsp&nbsp'+getWeekday();
  setTimeout(updateTime, 1000)
}

//不足10加上0
function formateData(date){
  return date>=10?date:'0'+date
}

//获取周几
function getWeekday(){
  let weekday=new Array(7)
  weekday[0]="星期天";
  weekday[1]="星期一";
  weekday[2]="星期二";
  weekday[3]="星期三";
  weekday[4]="星期四";
  weekday[5]="星期五";
  weekday[6]="星期六";
  return weekday[new Date().getDay()]
}

function resize() {
  let winH = window.innerHeight
  let winW = window.innerWidth
  let ratio = winW / winH
  let scale = winH / 1080
  $('body').css('width', ratio * 1080)
  $('body').css('transform', `scale(${scale},${scale}`)
}

function selectfrom(lowValue, highValue) {
  let choice = highValue - lowValue + 1
  return Math.floor(Math.random() * choice + lowValue)
}

resize()
$(window).resize(function () {
  resize()
})

$('.main-nav>.nav li').click(function () {
  $('.main-nav>.nav li').removeClass('active')
  $(this).addClass('active')
})

// 首页地图悬浮
$('.m-left .item').click(function(){
  $('.m-left .item').removeClass('active')
  $(this).addClass('active')
  let oindex = $(this).index()
  let str = $(this).text().trim()
  if(oindex != 0){
    $('.map').find('.point').hide()
    $('.map').find('.point').eq(oindex).show()
  }else{
    $('.map').find('.point').show()
  }
  $('.right-header').text(`${str}联网受理事件统计`)
})

// 模拟鼠标点击地图
mnclick()
function mnclick(){
  let itemArr = Array.from($('.m-left .item'))
  itemArr.reduce((p, x, m) => p.then(() => 
    
    new Promise(r => setTimeout(() => {
      r($(x).trigger("click"))
      if(m == 10){
        mnclick()
      }
    }, 2000))),
    Promise.resolve()
  )
}

onlineclick()
function onlineclick(){
  let index = 0
  let itemArr = Array.from($('.nav .item'))
  setInterval(function(){
    $('.nav .item').removeClass('active')
    $(itemArr[index]).addClass('active')
    index++
    if(index > itemArr.length-1){
      index = 0
    }
  },2000)
}

// 在线网点 
getpoint()
function getpoint(){
  let timer1
  let points = [{x:90,y:190},{x:120,y:350},{x:550,y:460},{x:550,y:340},{x:350,y:250},{x:450,y:550},{x:400,y:620},
    {x:350,y:680},{x:120,y:462},{x:420,y:680},{x:350,y:110},{x:300,y:210},{x:330,y:420},{x:370,y:254},
    {x:400,y:450},{x:410,y:150},{x:490,y:642},{x:500,y:678},{x:258,y:233},{x:358,y:468}] 
  let names = '市经信委 市科技厅 市公安厅 市民政厅 市财政厅 市住建厅 省国土厅 省农委 省质监局 省安监局 省保密局 省国税直属分局 省气象局 省文物局 省机关事务管理局 省卫计委 省物价局 省通管局 江苏检验检疫局'.split(' ')
  let arr = Array.from($('.se-result .item'))
  let index = 0
  $('.se-result .item').click(function(){
    $('.se-result .item').removeClass('active')
    $(this).addClass('active')
    
    let text = $(this).text().trim()
    names.filter((d,i) => {
      if(text==d){
        index = i
      }
    })
    let point = $('.pointofaim')
    point[0].style.left = points[index].x + 'px'
    point[0].style.top = points[index].y + 'px'
    point.show()
  })
  timer1 = setInterval(function(){
    $(arr[index]).trigger('click')
    index++
    if(index > arr.length-1){
      index = 0
    }
  },2000)
}


//千分制
function microme(b){
  var string=parseInt(b).toString().split('').reverse().join('');
  var arr=[];
  for(var i=string.length-1;i>=0;i--){
    arr.push(string.charAt(i))
    if(i%3==0 && i!=0){
      arr.push(',')
    }
  }
  return arr.join('')
}


$.fn.sscroll = function(cmd){
  this.each((_,el) => {
    let bar = $(el).find('.bar') //滚动块的高度
    let scrollbar = $(el).find('.scrollbar') //滚动区
    let body = $(el)
    let $layout = $('body') //大环境
    let lasts = 0 //上一次位置
    let barrotatio //比例
    let s = 0
    let y
    let flag
    let n = 0
    bar.mousedown(function(ev){
      flag = true
      y = ev.clientY
    })
    $layout.mousemove(function(ev){
      if(flag){
        s = ev.clientY - y
        n = s+lasts
        if(n <0 ){
          n = 0
        }else if(n > scrollbar.height()-bar.height()){
          n = scrollbar.height()-bar.height()
        }
        bar.css('top',`${n}px`)
        barrotatio = (n)/(scrollbar.height()-bar.height())
        bal(barrotatio)
      }
    })
    
    $layout.mouseup(function(){
      lasts = n
      flag = false
    })
    function bal(i){
      let  smallHeight = body.height();
      let bigHeight = el.scrollHeight;
      let range =  Math.floor((bigHeight-smallHeight)*i)
      body.scrollTop(range)
      scrollbar.css('top',`${range+14}px`)
    }
    body.on('mousewheel',function(e){
      var d = e.originalEvent.deltaY;
      var st = bar[0].offsetTop;
      if(d>0){
        let n = st+15
        if(n > (scrollbar.height()-bar.height())){
          n = scrollbar.height()-bar.height()
        }
        lasts = n
        bar.css('top',`${n}px`)
        barrotatio = (n)/(scrollbar.height()-bar.height())
        bal(barrotatio)
      }else{
        let n = st-15
        console.log(n)
        if(n < 0){
            n = 0
          }
        lasts = n
        bar.css('top',`${n}px`)
        barrotatio = (n)/(scrollbar.height()-bar.height())
        bal(barrotatio)
      }
    }) 
  })
}
$(function(){
  // $('.m-list').sscroll()
  $('.bom-list').sscroll()
  
  $('.ser-type').on('click','.li',function(){
    $('.m-bombBox').show()
  })
  $('.m-speak').on('click','.link',function(){
    $('.m-bombBox').show()
  })
  
  $('.hot-re').on('click','li',function(){
    $('.m-bombBox').show()
  })
  $('.artic-list').on('click','li',function(){
    $('.m-bombBox').show()
  })
  $('.m-bombBox').on('click','.closebox',function(){
    $('.m-bombBox').hide()
  })
})



function listCheck(){
  var item=$('.ul-list ul>label')
  let i=0
  var timer
  var len=item.length
  timer=setInterval(function(){
    i++
    if(i>=len){
      i=0
    }
    $('.ul-list ul>label').find('input').prop('checked',false)
    $('.ul-list ul>label').eq(i).find('input').prop('checked',true)
  },2000)
  item.on('mouseover',function(){
    clearInterval(timer)
    timer=null
  })
  item.on('mouseout',function(){
    clearInterval(timer)
    timer=setInterval(function(){
      i++
      if(i>=len){
        i=0
      }
      $('.ul-list ul>label').find('input').prop('checked',false)
      $('.ul-list ul>label').eq(i).find('input').prop('checked',true)
    },2000)
  })
}
listCheck()

